package cn.tedu.myweb.mapper;

import cn.tedu.myweb.model.Chats;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface ChatsMapper extends BaseMapper<Chats> {
    @Select("SELECT ch.chat,ch.master_id,ch.user_id,ch.create_time,ch.room_id\n" +
            "            FROM friend f\n" +
            "            LEFT JOIN room r\n" +
            "            ON f.friend_id=r.user_id2\n" +
            "            LEFT JOIN chat_history ch\n" +
            "            ON ch.room_id=r.id\n" +
            "            WHERE f.friend_name=#{friendName} and r.user_id1=#{userId} and f.user_id=#{userId} order by UNIX_TIMESTAMP(`create_time`);")
    List<Chats> getFriendChatHistory1(String friendName,int userId);

    @Select("SELECT ch.chat,ch.master_id,ch.user_id,ch.create_time,ch.room_id\n" +
            "            FROM friend f\n" +
            "            LEFT JOIN room r\n" +
            "            ON f.friend_id=r.user_id1\n" +
            "            LEFT JOIN chat_history ch\n" +
            "            ON ch.room_id=r.id\n" +
            "            WHERE f.friend_name=#{friendName} and r.user_id2=#{userId} and f.user_id=#{userId} order by UNIX_TIMESTAMP(`create_time`);")
    List<Chats> getFriendChatHistory2(String friendName,int userId);
}
